package com.jackie.springmvc.handlers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 

@Controller
public class HelloWorld {

	 
	 /**
	 10      * 1. 使用RequestMapping注解来映射请求的URL
	 11      * 2. 返回值会通过视图解析器解析为实际的物理视图, 对于InternalResourceViewResolver视图解析器，会做如下解析
	 12      * 通过prefix+returnVal+suffix 这样的方式得到实际的物理视图，然后会转发操作
	 13      * "/WEB-INF/views/success.jsp"
	 14      * @return
	 15      */
	      @RequestMapping("/helloworld/{id}")
	      public String hello(@PathVariable(value="id") Integer id){
	         System.out.println("hello world");
	         System.out.println("testPathVariable:" + id);
	         
	        return "result";
	     }
	      
	      @RequestMapping("/testPathVariable/{id}")
	      public String testPathVariable(@PathVariable(value="id") Integer id){
	          System.out.println("testPathVariable:" + id);
	          return "result";
	      }
	      
	 
	      @RequestMapping(value="/testRequestParam", method=RequestMethod.GET)
	      public String testRequestParam(@RequestParam(value="username") String username, @RequestParam(value="age", required=false, defaultValue="0") int age){
	          System.out.println("testRequestParam" + " username:" + username + " age:" +age);
	          return "result";
	      }
	      
	      @RequestMapping(value="/testRest/{id}", method=RequestMethod.GET)
	      public String testRestPut(@PathVariable(value="id") Integer id){
	          System.out.println("test post:" + id);
	          return "result";
	      }
	           
	   
	      @ResponseBody
	      @RequestMapping("/user")
	      public  String get(){
	      
	          return "hello";
	      }
	      
	   
}
